package wt;

use strict;
use warnings;

require Exporter;

our @ISA = qw(Exporter);
our $VERSION = '0.102080';
our @EXPORT = qw(
    ptln echo handle_file get_pid is_int
);

sub ptln($) { 
    my $s = shift; 
    $s="" if(!defined $s); 
    print $s."\n"; 
}

sub echo($){ print shift; }

sub handle_file($$){
    my ($file, $handler) = @_;

    open (F, $file) or die "$!";
    while(<F>){
        my $line = $_; 
        &$handler($line);
    }   
}

sub inc_hash(){
    my ($hash, $key) = @_; 

    if($hash->{$key}){ $hash->{$key}++; }   
    else{ $hash->{$key}=1; }   
}

#usage: get_pid( "org.apache.catalina.startup.Bootstrap", "java" )."\n";
sub get_pid($$) {

    return -2 if($#_ < 1);

    my $ret = -1;
    my ( $grepstr, $keyword ) = @_;

    open (PIPE, "ps -ef|grep $grepstr|");
    my @result = <PIPE>;

    foreach (@result) {
        my @str = split(" ",$_);
        if($_ =~ m/.*$keyword.*/)  {
            $ret = $str[1];
        }
    }

    return $ret;
}

sub is_int($){
 my $n = shift;
 (~$n & $n)? 0 : 1;
} 

1;

=head1 NAME

wt.pm - Daily Tool

=head1 SYNOPSIS

    handle_file( "url.list", 
        sub{ 
            print shift;
        }
    );

    inc_hash( \%hash , $key );


 Examples:

 See also:
    Nothing Here!

=head1 DESCRIPTION

utils function for daily work

Some detail description

=head1 AUTHOR

Rentie <rwtest@gmail.com>
Maintained by myself.

=head1 COPYRIGHT

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut
__END__
